<!-- 
      =============================================
            Quinta Pagina: All gifts
      =============================================     
  -->
  
    
   <div data-role="page"  id="giftshake-final" data-theme="f">
       
     
     <script type="text/javascript">
     
     $( "#giftshake-final" ).live( "pageinit", function( event ) { // 9fb3cc
       
       $('#giftshake-final a.backbutton').prepend('<div style="position: absolute; width: 16px; height: 17px; background: rgb(150, 174, 204); position: absolute; -webkit-transform: rotate(45deg); top: 3px; left: -8px; border: 1px solid rgba(0,0,0, 0.4); -webkit-box-shadow: 0 1px 0 rgba(255,255,255, 0.25), inset 0 1px 1px rgba(0,0,0, 0.2)"></div>');        
       $('#giftshake-final a.nextbutton').prepend('<div style="position: absolute; width: 16px; height: 17px; background: rgb(150, 174, 204); position: absolute; -webkit-transform: rotate(45deg); top: 3px; right: -8px; border: 1px solid rgba(0,0,0, 0.4); -webkit-box-shadow: 1px 0 0 rgba(255,255,255, 0.25), inset 1px 0 1px rgba(0,0,0, 0.2)"></div>');

       $("#giftshake-final #block_sn").css('visibility', 'hidden');
    });
     
     
       
     $( "#giftshake-final" ).live( "pageshow", function( event ) {
       
           var gift = getFromSession();
           var allproducts = '';
           var escaped_value;
           var arrProducts = []; 
           var prod;


          
          if (gift != null) 
           if (gift.products != null) { 
              allproducts = gift.products;
              $('#giftshake-final #gifts_in_shake').css('visibility', 'visible');
              $('#giftshake-final #gifts_in_shake').html(allproducts.length); 
            }
                   
          
          
          
          
          $.each( allproducts, function( key, value ) {
              escaped_value = value.replace(/(:|\.|\[|\])/g,'\\$1');   
              
              prod = {};
              
              // var index = value.match(/\[(\d+)\]/);
              var ptype = value.match(/\[([a-z-]+)\]/);   // riviste, ..
              var pcod = value.match(/\[([0-9]+)\]/);  // 001,002,..
              
              //alert(typeproduct[1] + ' ' + idnum[1]);
              
              
              
              
              
              // costruisco l'array delle scelte che poi lo passo in ajax allo script
              // per reperire i prodotti
              
              prod['type'] = ptype[1];
              prod['cod'] = pcod[1];
              
              
              arrProducts.push(prod);  // collection of objects (riviste, 001)

            
            });
            
            //alert(JSON.stringify(arrProducts));
            
            
            $.ajax({ url: "script_get_products.php",
            type: 'POST',
            //dataType: 'json',
            data: {products: JSON.stringify(arrProducts)}, //"item_type=" + param,
            success: function(data) {
              //alert(data);


                $("#giftshake-final div[data-role=content] ul").html(data);


                $("#giftshake-final div[data-role=content] ul" ).listview("refresh");
                $("#giftshake-final div[data-role=content]").iscrollview("refresh");



                $("#giftshake-final div[data-role=content] ul li a[name=deleteProd]").remove();


                var num_prodotti = arrProducts.length;
                var i = 0;
                var voti = 5; // num_persone del gruppo
                var gamma = 0;



                $("#giftshake-final div[data-role=content] ul li a h2").each(function (e) {

                    // calcolo un numero di voti per ciascun prodotto
                    // numero amici gruppo: 5
                    // numero prodotti nel giftshake: X = arrProducts.length
                    // max dim del giftshake finale : 5 prodotti


                    //gamma = 1 + Math.floor(Math.random() * 2);

                    if (i < voti) {

                    $(this).append("<h5 style='margin-bottom: 0px; margin-top:8px; color: #0066cc; font-style: italic'>" +
                            (voti - i) + " voti </h5>");

                    //$(this).append("<span style='margin-left:10px' class='ui-li-count'>" + (voti - i) + "</span>");

                    i++;
                    }
                    /*
                    if (i < 5) {

                        if (i == 0 | i == 1)
                            voti = 3;
                        else if (i == 2)
                            voti = 2;
                        else voti = 1;

                       $(this).append("<span style='margin-left:10px' class='ui-li-count'>" + voti + "</span>");

                        i++;
                    }
                    else
                        $(this).append("<span style='margin-left:10px' class='ui-li-count'> 0 </span>"); */
                });



//                $("#giftshake-final div[data-role=content] ul li a h2").append(
//                        '<span style="margin-left:10px" class="ui-li-count">4</span>');



            }
            }); // end ajax

         $("#giftshake-final #block_sn").css('visibility', 'initial');
         $("#giftshake-final div[data-role=content]").iscrollview("refresh");

           });
          


         
     </script>
     
     
    

     
    <div data-role="header" data-theme="f">
<!--       <a href="#page_giftlist" class="backbutton">Continua</a>       -->
      <h3>giftshake del gruppo</h3>
      <!--<a href="#" class="nextbutton ui-btn-right">Finish</a>-->
      <!-- <a id="" href="#popupDialog" class="rectbutton" data-rel="popup" data-position-to="window"  data-inline="true" data-transition="pop">Concludi</a> -->
    </div>
    <div data-role="content" data-iscroll="">
      <!-- content via ajax -->
      
      <h3 class="ui-title">Il Gruppo ha votato i prodotti e il giftshake finale è stato definito!</h3>

      <!--  Giftshake finale del gruppo -->
      <ul data-inset="true" data-role="listview"></ul>

        <div id="block_sn" style="visibility: hidden">
        <p>
        <fieldset class="ui-grid-a">
            <div class="ui-block-a">
                <a href="#" data-role="button" data-transition="flow" data-theme="c">Salva</a>
            </div>
            <div class="ui-block-b">
                <a href="page.survey.php" rel="external" data-role="button" data-transition="flow" data-theme="b">Notifica adesso!</a>
            </div>
        </fieldset>
        </p>
        </div>
      
    </div> <!-- end content -->

      
     
    <div data-role="footer" data-position="fixed" class="nav-glyphish-example" data-theme=c>
        <div data-role="navbar" class="nav-glyphish-example" >
          <ul>
            <li><a href="home.php" rel="external" id="home" data-icon="custom"><h4>Home</h4></a></li>
            <li><a href="#" id="search" data-icon="custom"><h4>Search</h4></a></li>
            <li><a href="#" id="gift" data-icon="custom">
                <span id="gifts_in_shake" class="ui-li-count" style="left:42px; top:-9px; visibility: hidden "></span>
                <h4>Giftshake</h4>
            </a>
            </li>
            <li><a href="#" id="wishlist" data-icon="custom"><h4>Preferiti</h4></a></li>
          </ul>
        </div>
        
     
        
      </div> <!-- footer -->
  </div>